/*
 * BBActionNewTower.java
 *
 * Created on March 10, 2008, 7:08 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package hextd.blackBox;

import hextd.tower.TowerFactory;
import hextd.util.Context;

/**
 *
 * @author hylke
 */
public class BBActionNewTower implements BBAction {
    
    private static final BlackBox.ActionType type = BlackBox.ActionType.NewTower;
    private int gameTime;
    private int row;
    private int col;
    private TowerFactory.type ttype;
    
    /** Creates a new instance of BBActionNewTower */
    public BBActionNewTower(int gameTime, int row, int col, TowerFactory.type t) {
        this.gameTime = gameTime;
        this.row = row;
        this.col = col;
        this.ttype = t;
    }
    
    @Override
    public BlackBox.ActionType getType() {
        return BBActionNewTower.type;
    }
    
    @Override
    public int getGameTime() {
        return this.gameTime;
    }
    
    @Override
    public void execute(Context c) {
        //System.out.println("BBActionNewTower::execute: "+c.gameTime+" Building Tower "+this.ttype.toString()+".");
        if (!c.blackBoxCurrent.newTower(this.col, this.row, this.ttype)) {
            System.err.println("BBActionNewTower::execute: Sync error: Tower build failed!");
        }
    }

    @Override
    public String getString() {
        return ""+this.gameTime+" N "+this.row+" "+this.col+" "+this.ttype.code+"\n";
    }
    
}
